package awt.awt04;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

public class menuDemo00 {
    private Frame fr=new Frame("测试菜单相关组件");

    // 创建菜单条
    MenuBar menuBar=new MenuBar();


    Menu fileMenu=new Menu("文件");
    Menu editMenu=new Menu("编辑");
    Menu formatMenu=new Menu("格式");

    MenuItem auto=new MenuItem("自动换行");
    MenuItem copy=new MenuItem("复制");
    MenuItem paste=new MenuItem("粘贴");

    MenuItem comment=new MenuItem("注释",new MenuShortcut(KeyEvent.VK_Q,true));
    MenuItem cancelComment=new MenuItem("取消注释");


    TextArea ta=new TextArea(6,30);



    public void init(){

        comment.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ta.append(e.getActionCommand());
            }
        });

        formatMenu.add(comment);
        formatMenu.add(cancelComment);

        editMenu.add(auto);
        editMenu.add(copy);
        editMenu.add(paste);
        editMenu.add(formatMenu);

        menuBar.add(fileMenu);
        menuBar.add(editMenu);


        fr.setMenuBar(menuBar);
        fr.add(ta);

        fr.pack();
        fr.setVisible(true);
    }

    public static void main(String[] args){
        new menuDemo00().init();
    }


}
